<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="材料名称" prop="materialName">
                <el-input v-model="queryParams.materialName" placeholder="请输入材料名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="materialList" row-key="materialId" default-expand-all :tree-props="{ children: 'updateRecords' }">
            <el-table-column label="材料ID" :show-overflow-tooltip="true" align="center" prop="materialId" />
            <el-table-column label="材料商" :show-overflow-tooltip="true" align="center"
                prop="materialSupplierName"></el-table-column>
            <el-table-column label="材料名称" :show-overflow-tooltip="true" align="center"
                prop="materialName"></el-table-column>
            <el-table-column label="材料简述" :show-overflow-tooltip="true" align="center"
                prop="materialBriefly"></el-table-column>
            <el-table-column label="点赞数" width="80" align="center" prop="likes"> </el-table-column>
            <el-table-column label="访问量" width="80" align="center" prop="visits"> </el-table-column>
            <el-table-column label="上传时间" align="center" :show-overflow-tooltip="true" prop="createTime" />
            <el-table-column label="材料状态" width="80" align="center" prop="materialStatus">
                <template #default="scope">
                    <dict-tag :options="material_status" :value="scope.row.materialStatus" />
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button link type="primary" icon="Stamp" size="small" v-hasPermi="['decor:material:edit']"
                        @click="handleView(scope.row)">审核</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script setup>
import { listMaterial } from "@/api/decor/materialAudit";
const router = useRouter();
const { proxy } = getCurrentInstance();
const { material_status } = proxy.useDict('material_status');
// 表格数据
const materialList = ref([]);
// 遮罩层
const loading = ref(true);
// 显示搜索条件
const showSearch = ref(true);
// 总条数
const total = ref(0);
const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        materialName: null,
        // orderByColumn: 'materialId',
        // isAsc: 'desc',
        needAdminSort: false
    },
});

const { queryParams } = toRefs(data);

/** 查询材料列表 */
function getList() {
    loading.value = true;
    listMaterial(queryParams.value).then(response => {
        materialList.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
}

/** 审核按钮操作 */
function handleView(row) {
    router.push('/materialAudit/auditMaterialAudit/' + row.materialId + '/audit')
}

getList();
</script>
<style lang="scss" scoped>
::v-deep(.el-button--primary.is-link) {
    color: #EF5A42;
}
</style>